layui.use(['table', 'form', 'vip_table', 'jquery', 'fms_util', 'element','laydate'], function () {
    // 操作对象
    var form = layui.form,
        table = layui.table,
        vipTable = layui.vip_table,
        fmsUtil = layui.fms_util,
        element = layui.element,
        laydate = layui.laydate,
        $ = layui.jquery;

    laydate.render({elem:'#startTime'});
    laydate.render({elem:'#endTime'});

    //表格加载
    var where = {
        data:[
            {stationId:"123",level:"Minor",mark:1,possibleReason:"警告",supplierNo:"2018/01/03",supplierEnd:"2018/07/03"}
        ]
    };

    var tableIns = {};

    initTable(where);
    function initTable(where) {
        tableIns = vipTable.bdTable({
            table: table,
            elem: "#dataTable",
            limit: 6,
            cols: [[
                {type: 'numbers', title: '序',width:'5%', align: 'center'},
                // {type:'checkbox'},
                {field: 'stationId', title: '告警编号', align: 'center'},
                {title: '告警级别', align: 'center',toolbar: '#htmlStyle'},
                {field: 'mark', title: '告警标识', align: 'center'},
                {field: 'possibleReason', title: '告警库原因', align: 'center'},
                {field: 'supplierNo', title: '开始时间', align: 'center'},
                {field: 'supplierEnd', title: '结束时间', align: 'center'},
                {title: '操作', align: 'center', toolbar: '#barOption'}
            ]],
            data:where.data
        });
    }
    //tab点击切换
    $('.tab_card li').on('click',function(){
        $('#reset-btn').click();
        var type=$(this).attr('data-type');
        switch (type){
            case '1':
                if(where.state>=0){delete where.state}
                if(where.state2>=0){delete where.state2}

                 break;
            case '2':
                where.state2=2;
                where.state=0;

                break;

        }
        tableIns.reload({
            where: where,

        });
    });
    //搜索
    form.on('submit(search)', function (data) {
        where = $.extend(where, data.field);
        var reloadWhere = fmsUtil.filterObject(where);//筛选掉空的数据
        where.pageNo = 1;
        tableIns.reload({
            searchState: true,
            where: reloadWhere
        });
        initTable(reloadWhere);
        return false;
    });

    table.on('tool(dataTable)', function (obj) {
        var layEvent = obj.event;
        var value = obj.value,//得到修改后的值
            data = obj.data,//得到所在行所有键值
            field = obj.field; //得到字段

        if (layEvent === 'edit') {
            active.edit(data.id);
        } else if (layEvent === 'dalete') {
            active.dalete(data.id);
        }
    });

    var active = {
         //删除
        dalete: function () {
            parent.layer.confirm('是否确定删除？', function(index){
                fmsUtil.msg('删除成功',{callBack:function(){
                        tableIns.reload({data:[]});
                    }});
                layer.close(index);
            });
        }
    };


});